package com.ruoyi.system.service.mongo;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.mongodb.AllSchool;
import com.ruoyi.system.domain.mongodb.Klasses;
import com.ruoyi.system.domain.mongodb.Schools;
import com.ruoyi.system.mongo.AllSchoolDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * @author yangtao
 * @since 2021-02-24 11:28
 */
@Service
public class AllSchoolServiceImpl implements AllSchoolService{

    @Autowired
    private AllSchoolDao schoolDao;

    @Override
    public List<AllSchool> selectSchoolByCode(String eareCode) {
        return schoolDao.selectSchoolByCode(eareCode);
    }

    @Override
    public List<Klasses> selectClassList(String schoolId) {
        return schoolDao.selectClassList(schoolId);
    }

    @Override
    public int save(Schools schools) {

        AllSchool school = schoolDao.queryByNamesAndCode(schools.getNames(), schools.getEareCode());
        if (school!=null){
            return 2;
        }
        Schools save = schoolDao.save(schools);
        if(StringUtils.isNotNull(save)){
            return 1;
        }
        return 0;
    }

    @Override
    public PageInfo<Schools> selecSchoolPage(String schoolName,String eareCode, Integer pageNum, Integer pageSize) {

        return schoolDao.selectSchoolAll(schoolName,eareCode,pageNum,pageSize);
    }

    @Override
    public void deleteSchoolById(String id) {
        schoolDao.deleteSchoolById(id);
    }

    @Override
    public Integer updateSchool(String schoolId, String schoolName, String eareCode) {
        return schoolDao.updateSchool(schoolId,schoolName,eareCode);
    }
}
